package NO3_LinkedList;

/**
 * 2025-08-11
 * 复习链表题目
 */
public class ReviewMain {
    public static void main(String[] args) {
        ListNode listNode = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5)))));
        ListNode.printList(listNode);
        ListNode reverseListNode = reverseList(listNode);
        ListNode.printList(reverseListNode);
    }

    /**
     * 反转链表
     */
    public static ListNode reverseList(ListNode head) {
        ListNode pre = null; // 前一个节点
        ListNode cur = head; // 当前节点
        while (cur != null){
            ListNode temp = cur.next;
            cur.next = pre;
            pre = cur;
            cur = temp;
        }
        return pre;
    }
}
